package gov.trasport.online.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import gov.trasport.online.enums.ActionEnum;
import gov.trasport.online.model.Employee;
import gov.trasport.online.service.EmployeeReportManager;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class EmployeeReportController {

	static Logger logger = Logger.getLogger(EmployeeReportController.class);

	@Autowired
	@Qualifier(value = "empReportManager")
	private EmployeeReportManager employeeReportManager;

	public EmployeeReportManager getEmployeeReportManager() {
		return employeeReportManager;
	}

	public void setEmployeeReportManager(
			EmployeeReportManager employeeReportManager) {
		this.employeeReportManager = employeeReportManager;
	}

	@RequestMapping("/employeeReportAll")
	public ModelAndView employeeReportAll(HttpServletRequest request,
			HttpServletResponse response) {
		//System.out.println("Action Here:"+ActionEnum.EMPLOYEEREPORTALL.toString());
		request.setAttribute("actionPage",
				ActionEnum.EMPLOYEEREPORTVIEW.toString());// request.getRequestURI().toUpperCase();
		
		logger.info(ActionEnum.EMPLOYEEREPORTALL.toString());
		List<Employee> employeeReportList = employeeReportManager
				.getAllEmployeeReport();
		ModelAndView modelList = new ModelAndView("employeeReportAll");
		modelList.addObject("employeeReportAllEntity", employeeReportList);
		logger.info("all Employee Report  started" + employeeReportList);
		return modelList;
	}

	@RequestMapping("/employeReportView")
	public ModelAndView employeReportView(HttpServletRequest request,
			HttpServletResponse response) {
		//System.out.println("Action Here:"+ActionEnum.EMPLOYEEREPORTVIEW.toString());
		request.setAttribute("actionPage",
				ActionEnum.EMPLOYEEREPORTVIEW.toString());// request.getRequestURI().toUpperCase();
		logger.info(ActionEnum.EMPLOYEEREPORTVIEW.toString());
		String objectId = request.getParameter("singleView");
		Employee employeeReportList = employeeReportManager.getReport(objectId);
		ModelAndView modelList = new ModelAndView("employeReportView");
		modelList.addObject("employeReportViewEntity", employeeReportList);
		logger.info("all Employee Report  started" + employeeReportList);
		return modelList;
	}
}
